//
//  HomeComTriggerView.m
//  Ginix
//
//  Created by fzq on 2025/2/23.
//

#import "HomeComTriggerView.h"
#import "HomeMindDataCell.h"
@interface HomeComTriggerView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView * listView;
@property (nonatomic,strong) YYLabel * infoLabel;
@property (nonatomic,strong) NSArray * listArray;
@end

@implementation HomeComTriggerView

-(void)setSubViewLayout{
    
    [super setSubViewLayout];
    self.titleLabel.text = @"可能引发的疾病";

    [self addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(300 * FMScaleX, 130 * FMScaleX));
        make.top.equalTo(self.iconView.mas_bottom).offset(15 * FMScaleX);
        make.centerX.equalTo(@0);
    }];
    [self addSubview:self.listView];
    [_listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.infoLabel.mas_bottom).offset(7 * FMScaleX);
        make.size.mas_offset(CGSizeMake(300 * FMScaleX, 320 * FMScaleX));
        make.centerX.equalTo(@0);
    }];
}

-(void)setInfoModel:(HomeAllCheckInfoModel *)infoModel{
    
    self.listArray = infoModel.attack;
    [self.listView reloadData];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.listArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 38 * FMScaleX;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeMindDataCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeMindDataCell"];
    HomeAllAttackModel * model = self.listArray[indexPath.row];
    if (model) {
        [cell setAttModel:model];
    }
    
    return cell;
}

-(YYLabel *)infoLabel{
    
    if(!_infoLabel){
        _infoLabel = [[YYLabel alloc]init];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = Regular(13);
        _infoLabel.textContainerInset = UIEdgeInsetsMake(3, 3, 3, 3 );
        
        NSMutableAttributedString * attri = [[NSMutableAttributedString alloc]initWithString:@" 报告是通过中医监测对局部病机会引发的所有疾病风险的总结，是通过病机到疾病风险的推演预测，不是传统意义上的医学疾病诊断。评估值范围(1-100),显性强度代表*/推演预测的评估。\n风险提示：报告内容仅供参考，不能替代专业医生的诊断、治疗或建议，如有实际疾病请线下就医。" attributes:@{NSForegroundColorAttributeName:RDRGB(0x000000)}];
        
        [attri yy_setColor:RDRGB(0x9A7742) range:[attri.string rangeOfString:@"推演预测"]];
        [attri yy_setColor:RDRGB(0x9A7742) range:[attri.string rangeOfString:@"(1-100)"]];
        [attri yy_setColor:RDRGB(0x9A7742) range:[attri.string rangeOfString:@"评估"]];
        [attri yy_setColor:RDRGB(0x9A7742) range:[attri.string rangeOfString:@"风险提示：报告内容仅供参考，不能替代专业医生的诊断、治疗或建议，如有实际疾病请线下就医。"]];
        _infoLabel.attributedText = attri;
                
    }
    return _infoLabel;
}

-(UITableView *)listView{
    
    if (!_listView) {
        _listView = [[UITableView alloc]init];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.showsVerticalScrollIndicator = NO;
        _listView.showsHorizontalScrollIndicator = NO;
        _listView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listView.backgroundColor = UIColor.clearColor;
        [_listView registerClass:[HomeMindDataCell class] forCellReuseIdentifier:@"HomeMindDataCell"];
    }
    return _listView;
}
-(NSArray *)listArray{
    
    if (!_listArray) {
        _listArray = [[NSArray alloc]init];
    }
    return _listArray;
}
@end
